const getDefaultState = () => {
  return {
    curCommunity: ""
  };
};

const state = getDefaultState();

const mutations = {
  SET_CUR_COMMUNITY: (state, curCommunity) => {
    state.cur_community = curCommunity;
    localStorage.setItem("curCommunity", JSON.stringify(curCommunity));
    location.reload();
  }
};

const getters = {
  getCurCommunity: () => {
    let curCommunity = localStorage.getItem("curCommunity");
    if (curCommunity) {
      return JSON.parse(curCommunity);
    }
    return null;
  }
};

const actions = {
  curCommunity({ commit }, curCommunity) {
    commit("SET_CUR_COMMUNITY", curCommunity);
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
};
